﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using DLM.Infrastructure.Domain;

namespace DLM.Domain.Model
{
    public class Supplier : IValidatableObject, IAggregateRoot
    {
        public int SID { get; set; }
        public int MID { get; set; }

        [StringLength(30,ErrorMessage="最大长度为30")]
        public string Name { get; set; }

        public string Address { get; set; }

             [StringLength(20, ErrorMessage = "最大长度为20")]
        public string Phone { get; set; }

         [RegularExpression(@"^[1-9]\d*$", ErrorMessage = "顺序必须为正整数")]
        public int Order { get; set; }
        public System.DateTime CreateDate { get; set; }

        public virtual Modality Modality { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (string.IsNullOrEmpty(Name))
            {
                yield return new ValidationResult("供应商名称不能为空", new string[] { "Name"});
            }

            if (string.IsNullOrEmpty(Phone))
            {
                yield return new ValidationResult("供应商电话不能为空", new string[] { "Phone" });
            }
        }
    }
}
